/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.haw.dbp.a4.gui;

import dc.connectionmanager.database.DBConnectionManager;
import dc.connectionmanager.logic.ICallback;
import de.haw.dbp.a4.logic.DBCommand;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

/**
 *
 * @author jmenzel
 */
public class JPShowMedia extends ADBListPanel
{
    public JPShowMedia(MainFrame rParent, DBConnectionManager cDB)
    {
        super(rParent, cDB);
        
        this.cb_filter2.setEnabled(false);
        this.cb_filter2.setVisible(false);
    }

    @Override
    public void loadDefaultData(ICallback cb) 
    {
        ((DBCommand)this.dbcm.getCommandClass()).getAllMedia(cb);
    }

    @Override
    protected void loadDataWithFilter(ICallback cb)
    {
        int f1 = cb_filter.getSelectedIndex();
        String qs = this.jtf_quicksearch.getText();
        
        if(f1 > 0)
        {
            ((DBCommand)this.dbcm.getCommandClass()).getMediaByMediumNameAndMTyp(cb, qs, ""+f1);
        }
        else 
        {
            ((DBCommand)this.dbcm.getCommandClass()).getMediaByMediumName(cb, qs);
        }
    }

    @Override
    protected void loadFilterCombobox(ICallback cb)
    {
        ((DBCommand)this.dbcm.getCommandClass()).getAllMedienTyp(cb);
    }

    @Override
    protected void l_addItemOnClick(MouseEvent evt)
    {
        new FNewMedia(this, dbcm);
    }
    
    public void reloadData()
    {
        this.loadDataWithFilter(new ICallback() 
        {

            @Override
            public void handleResult(Object result)
            {
                if(result != null)
                {
                    fillTable((ArrayList<ArrayList<String>>)result);
                }
            }
        });
    }

    
}
